-
-
Notifications
You must be signed in to change notification settings - Fork 2
refactor(useKeydown): optimize keydown event handling #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
} | ||
|
||
if (getCurrentScope()) { | ||
const stopListening = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is your philosophy behind const functions and when to use them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used to write functions via const, but on top level it's converted by antfu eslint plugin automatically, unlike nesting 🥲
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may be reading this wrong, but I really thing you might benefit from using useRegistry instead of managing handlerMap.
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
function startGlobalListener () { | ||
if (typeof document === 'undefined') return | ||
|
||
if (!globalListener) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whenever if { ... }
guards most of the logic within a function it should be replaced with early exit if (!..) return
, so we avoid unnecessary indentation and the inner logic is easier to read/scan-through.
There are 3 methods here that would benefit from this quick refactoring.
use registrar and single event listener to listen to keydown in a more performant way